/**
 * 
 * 
 * Created on 2 mei 2011 @ 13:48:20 by Laurens Andriessen
 */

package combat.dudes.server.protocol.implementation;

import gnu.cajo.invoke.Remote;

import java.rmi.RemoteException;

import combat.dudes.DudesConfig;
import combat.dudes.protocol.data.DoublePoint;
import combat.dudes.protocol.data.PhysicalObject;
import combat.dudes.protocol.interfaces.ProjectileInt;
import combat.dudes.protocol.types.PhysicalObjectType;
import combat.dudes.protocol.types.ProjectileType;
import combat.dudes.server.ServerApp;


/**
 * 
 * @author Laurens Andriessen
 * @version 1.0
 */
public class Projectile extends PhysicalObject implements ProjectileInt {

	private static final long serialVersionUID = 1L;

	// [ Inherited from PhysicalObject ]
	// String name
	// DoublePoint position
	// int altitude
	// double direction
	// double speed
	DoublePoint source = null;
	Object target = null;
	double maxDistance = 0.0;
	ProjectileType projectileType = ProjectileType.UNKNOWN;

	public Projectile() {
		setType(PhysicalObjectType.PROJECTILE);
	}

	public Projectile(DoublePoint source, Object target, double maxDistance, ProjectileType projectileType) {
		setType(PhysicalObjectType.PROJECTILE);
		setSource(source);
		setTarget(target);
		setMaxDistance(maxDistance);
		setProjectileType(projectileType);
		setSpeed(DudesConfig.SharedVars.getMaxSpeed(projectileType));
		setPosition(source);
		setName(projectileType + "-" + getObjID());
	}

	@Override
	public DoublePoint getSource() {
		return source;
	}
	@Override
	public void setSource(DoublePoint source) {
		this.source = source;
	}

	@Override
	public Object getTarget() {
		return target;
	}
	@Override
	public void setTarget(Object target) {
		this.target = target;
	}

	@Override
	public double getMaxDistance() {
		return maxDistance;
	}
	@Override
	public void setMaxDistance(double maxDistance) {
		this.maxDistance = maxDistance;
	}

	@Override
	public ProjectileType getProjectileType() {
		return projectileType;
	}
	@Override
	public void setProjectileType(ProjectileType projectileType) {
		this.projectileType = projectileType;
	}

	@Override
	public Remote getTarget_Remote() {
		try {
			return new Remote(getTarget());
		} catch(RemoteException e) {
			ServerApp.onError("@Projectile.java, getTarget_Remote()", e, false);
		}
		return null;
	}
}
